package com.blb.gateway_service.config;

import com.blb.common.utils.RsaUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.io.File;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.List;

/**
 * 读取配置文件的配置类 properties，yml
 */
@Data
@Configuration
//读取配置文件的注解
@ConfigurationProperties(prefix = "blb.jwt")
public class JwtProperties {

    private List<String> whiteList;//白名单
    private String pubKeyPath;//公钥路径
    private String cookieName;//cookie名称
    private PublicKey publicKey;//公钥

    //在构造方法之后自动执行
    @PostConstruct
    public void init(){
        try {
            //读取公钥内容
            this.publicKey = RsaUtils.getPublicKey(this.pubKeyPath);
        }catch (Exception ex){
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }
}
